<template>
  <div class="admin-works">
    <ul class="menu">
      <li :class="['content', menuActive == index ? 'active-content' : '']" v-for="(item, index) in menuList" :key="index" @click="handleMenu(index)">
        {{ item }}
      </li>
    </ul>
    <div class="work-admin" v-show="menuActive == 1">
      <MyHeader>
        <div slot="title">作品管理</div>
      </MyHeader>
      <div class="works-list">
        <div class="works upload-icon">
          <div class="box" @click="goUpload">
            <div class="content-box">
              <img src="@/static/img/editPersonalHome/upload_icon.png" alt="" />
              <div>上传作品</div>
            </div>
          </div>
        </div>
        <div
          class="works"
          v-for="(item, index) in artWorkList"
          :key="index"
          @mouseleave="handleMouseLeave" @mouseenter="handleMouseEnter(item.data_id)"
        >
          <div v-show="enterWork === item.data_id" class="mark all-center">
            <i class="el-icon-edit" @click.stop="goEdit(item.data_id)" style="font-size: 32px;margin-right: 15px;"></i>
            <i class="el-icon-delete" @click.stop="deleteWork(item.data_id)" style="font-size: 32px;margin-right: 15px;"></i>
          </div>
          <div v-if="item.is_famous === 1" class="famous all-center">
            代表作
          </div>
          <div class="img-content">
            <el-image fit="cover" class="img" :src="item.thumbnail" alt="" />
          </div>
          <div class="title">
            {{ item.name }}
          </div>
          <div class="second-title">
            {{ series.find((s) => s.data_id == item.type)?.name }}
          </div>
          <div class="collect">
            <img src="@/static/img/favorite_grey.png" alt="" />
            {{ item.focus_total }}
          </div>
        </div>
      </div>
      <Pagin
        ref="page"
        v-show="artWorkList.length !== 0"
        :func="getDataList"
        :pagesSizes="[10, 20, 30, 50]"
        :sizeNum="10"
        :layout="'prev, pager, next'"
        background
        :position="'center'"
        class="pagin"
      ></Pagin>
    </div>
    <div class="new-work-upload" v-show="menuActive == 0">
      <UploadWorks ref="uploadWorks" :data_id="data_id" />
    </div>
    <div class="work-famous-admin" v-show="menuActive == 2">
      <AdminFamousWorks @goUpload="goUpload" @goEdit="goEdit" ref="adminFamousWorks" />
    </div>
  </div>
</template>

<script>
import Pagin from "@/components/pagin.vue";
import MyHeader from "./common/myHeader.vue";
import UploadWorks from "../uploadWorks"
import AdminFamousWorks from "./adminFamousWorks"
export default {
  name: "",
  middleware: 'identityInfo',
  components: {
    Pagin,
    MyHeader,
    UploadWorks,
    AdminFamousWorks
  },
  props: {},
  data() {
    return {
      data_id: '',
      artWorkList: [],
      series: [],
      menuActive: 0,
      menuList: [
        '新作品上传',
        '作品管理',
        '代表作管理'
      ],
      enterWork: ''
    };
  },
  computed: {},
  watch: {},
  created() {},
  mounted() {
    this.refresh();
    this.$api.getProductType({}).then((res) => {
      this.series = Array.isArray(res.result.item_list)
        ? res.result.item_list
        : [];
    });
  },
  methods: {
    // handleCollect() {
    //   this.collectActive = !this.collectActive;
    // },
    handleMenu(index) {
      this.menuActive = index
      if (index == 1) {
        this.refresh()
      } else if (index == 2) {
        this.$refs.adminFamousWorks.refresh()
      } else {
        this.data_id = ''
      }
    },
    handleMouseEnter(id) {
      this.enterWork = id
    },
    handleMouseLeave() {
      this.enterWork = ''
    },
    goEdit(data_id) {
      this.menuActive = 0
      this.data_id = data_id
    },
    deleteWork(data_id) {
      this.$confirm('此操作将永久删除该文件, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.$api.deleteArtWorks({data_id}, {}).then(res => {
          if (res.status === '$SUCCESS') {
            this.$message.success('删除成功')
            this.refresh()
          }
        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        });
      });
    },
    getDataList(page, page_size, callback) {
      // 这里要写接口然后把数据和total丢进去
      this.$api
        .getWorksList({
          work_type: 1,
          art_id: this.$store.state.user.info?.user_info?.art_info?.data_id,
          page_num: page,
          page_count: page_size,
          recycle: 0
        })
        .then((res) => {
          this.artWorkList = Array.isArray(res.result.item_list)
            ? res.result.item_list
            : [];
          callback(this.artWorkList, this.artWorkList.length);
        });
    },
    goUpload() {
      // this.$router.push("/editPersonalHome/uploadWorks");
      // this.$emit('changeTab')
      this.menuActive = 0
      this.data_id = ''
    },
    // 重置翻页组件的方法
    refresh() {
      this.$refs.page.refresh();
    },
  },
};
</script>

<style scoped lang="less">
.admin-works {

  .menu {
    height: 100%;
    margin-right: 90px;
    margin-bottom: 50px;
    margin: 0 90px 50px 100px;

    .content {
      // width: 150px;
      line-height: 24px;
      margin-right: 80px;
      display: inline-block;
      font-size: 24px;
      color: #999;
      cursor: pointer;
      list-style-type: none;

      &.active-content {
        color: #000;
      }

      &:last-child {
        margin-bottom: 0;
      }
    }
  }
  .works-list {
    padding: 40px 45px;
    background: #fff;
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
  }

  .works-list::after {
    content: "";
    flex: 0 0 320px;
    // border: 1px solid #fff;
    // box-sizing: border-box;
  }

  .upload-icon {
    width: 320px;
    height: 312px;

    .box {
      width: 322px;
      height: 242px;
      background: #f3f4f4;
      border: 1px solid #ccc;
      box-sizing: border-box;
      display: flex;
      justify-content: center;
      align-items: center;
      cursor: pointer;

      .content-box {
        text-align: center;

        img {
          width: 56px;
          height: 56px;
          margin-bottom: 15px;
        }

        div {
          line-height: 16px;
          font-size: 16px;
          color: #999;
        }
      }
    }
  }

  .works {
    width: 320px;
    margin-bottom: 40px;
    position: relative;

    .mark {
      position: absolute;
      left: 0;
      top: 0;
      width: 100%;
      height: 242px;
      background-color: #000;
      opacity: 0.6;
      z-index: 999;

      .el-icon-edit,
      .el-icon-delete {
        cursor: pointer;
      }
    }

    .famous {
      // width: 48px;
      padding: 5px;
      height: 24px;
      position: absolute;
      top: 12px;
      left: 12px;
      background-color: #000;
      opacity: 0.5;
      font-size: 12px;
      font-weight: 600;
      color: #FFFFFF;
      z-index: 99;
    }

    &:not(.upload-icon) {
      cursor: pointer;
    }

    &:nth-child(3n) {
      margin-right: 0;
    }

    .img-content {
      width: 100%;
      height: 240px;
      position: relative;

      .img {
        width: 100%;
        height: 100%;
      }
    }

    .title {
      margin: 12px 0 8px;
      line-height: 16px;
      font-size: 16px;
      font-weight: 600;
      color: #000;
    }

    .second-title {
      line-height: 16px;
      font-size: 16px;
      font-weight: 600;
      color: #999;
      margin-bottom: 8px;
    }

    .collect {
      color: #999;
      font-size: 16px;
      line-height: 12px;

      img {
        // width: 30px;
        width: 16px;
        height: 16px;
        position: relative;
        top: -3px;
        margin-right: 9px;
      }
    }
  }

  .pagin {
    background: #fff;
  }
}
</style>
